package com.ngovanhau.justsort.model;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

import com.ngovanhau.justsort.MySprite;

import android.content.Context;


public class LoadResourcesNumber extends MySprite{
	private BitmapTextureAtlas[] number_BTA;
	private TextureRegion[] number_TR;
	
	private BitmapTextureAtlas[] characters_BTA;
	private TextureRegion[] characters_TR;
	
	private BitmapTextureAtlas[] number_red_BTA;
	private TextureRegion[] number_red_TR;
	
	private BitmapTextureAtlas[] characters_red_BTA;
	private TextureRegion[] characters_red_TR;
	
	public int size = 0;
	
	public LoadResourcesNumber(){
		this.size = LevelSetting.rowLevel*LevelSetting.columnLevel;
		
	}
	
	public TextureRegion getResourceName(int i){
		return number_TR[i];
	}
	
	public TextureRegion getResourceNameRed(int i){
		return number_red_TR[i];
	}
	
	public TextureRegion getResourceCharactersName(int i){
		return characters_TR[i];
	}
	
	public TextureRegion getResourceCharactersNameRed(int i){
		return characters_red_TR[i];
	}
	
	public void onLoadResources(Engine engine, Context context){
		this.engine = engine;
		this.context = context;
		
		number_BTA = new BitmapTextureAtlas[size];
		number_TR = new TextureRegion[size];
		
		number_red_BTA = new BitmapTextureAtlas[size];
		number_red_TR = new TextureRegion[size];
		
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("images/wrong/");
		for(int i =0; i< size ; i++){
			number_BTA[i] = new BitmapTextureAtlas(256,256);
			number_TR[i] = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.number_BTA[i], context, Integer.toString(i+1)+ ".png",0,0);
			engine.getTextureManager().loadTexture(number_BTA[i]);
		}
		
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("images/right/");
		for(int i =0; i< size ; i++){
			number_red_BTA[i] = new BitmapTextureAtlas(256,256);
			number_red_TR[i] = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.number_red_BTA[i], context, Integer.toString(i+1)+ ".png",0,0);
			engine.getTextureManager().loadTexture(number_red_BTA[i]);
		}
	}
	
	public void onLoadCharactersResources(Engine engine, Context context){
		this.engine = engine;
		this.context = context;
		
		characters_BTA = new BitmapTextureAtlas[size];
		characters_TR = new TextureRegion[size];
		
		characters_red_BTA = new BitmapTextureAtlas[size];
		characters_red_TR = new TextureRegion[size];
		
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("images/wrong/");
		for(int i =0; i< size ; i++){
			characters_BTA[i] = new BitmapTextureAtlas(256,256);
			characters_TR[i] = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.characters_BTA[i], context, ((char) (i + 'a'))+ ".png",0,0);
			engine.getTextureManager().loadTexture(characters_BTA[i]);
		}
		
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("images/right/");
		for(int i =0; i< size ; i++){
			characters_red_BTA[i] = new BitmapTextureAtlas(256,256);
			characters_red_TR[i] = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.characters_red_BTA[i], context, ((char) (i + 'a'))+ ".png",0,0);
			engine.getTextureManager().loadTexture(characters_red_BTA[i]);
		}
	}
}
